#!/usr/bin/python
# -*- encoding: utf-8

from keras.models import Sequential
from keras.layers import Dense
from keras.preprocessing import sequence
import numpy, warnings

numpy.set_printoptions(linewidth=1000)
numpy.random.seed(7)
warnings.filterwarnings("ignore")
path = u'/Users/scottdu/rongshi/data/stock_selection_data/monthly/end/feature_v2/training/12m_3_18/201501-201512_train.csv'
# dataset = numpy.loadtxt('pima-indians-diabetes.csv', delimiter=',')
dataset = numpy.loadtxt(path, delimiter=',', skiprows=1, usecols={1, 2, 3, 4})
#X = dataset[:,0:8]
#Y = dataset[:,8]
X = dataset[:,0:3]
Y = dataset[:,3]



# create model
model = Sequential()
model.add(Dense(12, input_dim=3, init='uniform', activation='relu'))
# model.add(Dense(8, init='uniform', activation='relu'))
model.add(Dense(1, init='uniform', activation='sigmoid'))


# Compile mode
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

# Fit the model
model.fit(X, Y, epochs=150, batch_size=10)

# evaluate the model
scores = model.evaluate(X, Y)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))


path = u'/Users/scottdu/rongshi/data/stock_selection_data/monthly/end/feature_v2/testing/201601pred.csv'
# dataset = numpy.loadtxt('pima-indians-diabetes.csv', delimiter=',')
dataset = numpy.loadtxt(path, delimiter=',', skiprows=1, usecols={1, 2, 3})
X_predict = dataset[:,0:3]
predictions = model.predict(X_predict)
numpy.savetxt(u'/tmp/201601pred.csv', predictions)
print(predictions)


